package 树.红黑树;

/**
 * Created by yang on 2016/9/13.
 */
public class RBTreeUtils {

    RBTree root = null;

    /**
     * the function declare the operation of rotate right
     * @param rotate node of rotate
     * @return
     */
    public void rotate_R(RBTree rotate) {
        // 保存旋转节点的左节点
        RBTree rotate_lChild = rotate.lChild;
        //置空旋转节点的左节点
        rotate.lChild = null;
        // 保存左节点的右节点
        RBTree rotate_lChild_rChild = rotate_lChild.rChild;
        // 置空右节点
        rotate_lChild.rChild = null;

        //改变父节点
        rotate_lChild.parents = rotate.parents;
        rotate.parents = rotate_lChild;
        rotate.lChild = rotate_lChild_rChild;
    }

    /**
     * the function declare operation of rotate left
     * @param rotate node of rotate
     */
    public void rotate_L(RBTree rotate) {
        // 保存被旋转节点的右孩子
        RBTree rChild = rotate.rChild;
        // 置空右孩子
        rotate.rChild = null;
        // 保存右孩子的左节点
        RBTree rChile_lChild = rChild.lChild;
        // 置空左节点
        rChild.lChild = null;

        // 设置父节点
        rChild.parents = rotate.parents;
        rotate.parents = rChild;
        rotate.rChild = rChile_lChild;
    }
}
